package com.vhans.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vhans.core.domain.Card;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.db.service.CardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠卡片Controller控制器
 *
 * @author vhans
 * @date 2023-06-04
 */
@Api(tags = "优惠卡片模块")
@RestController
@RequestMapping("/dome/card")
public class CardController extends BaseController {

    @Autowired
    private CardService cardService;

    /**
     * 查询用户优惠卡片列表
     *
     * @return 优惠卡片集合
     */
    @ApiOperation(value = "查询用户优惠卡片列表")
    @SaCheckPermission("dome:card:query")
    @GetMapping(value = "/list")
    public Result<List<Card>> list() {
        return Result.success(cardService.selectCardListByUserId());
    }

    /**
     * 新增优惠卡片
     *
     * @param card 优惠卡片
     * @return 影响行
     */
    @ApiOperation(value = "新增优惠卡片")
    @SaCheckPermission("dome:card:add")
    @PostMapping("/add")
    public Result<?> add(@Validated @RequestBody Card card) {
        return toAjax(cardService.insertCard(card));
    }

    /**
     * 更新优惠卡片价格
     *
     * @param card 优惠卡片
     * @return 影响行
     */
    @ApiOperation(value = "更新优惠卡片价格")
    @SaCheckPermission("dome:card:update")
    @PostMapping("/update")
    public Result<?> update(@Validated @RequestBody Card card) {
        return toAjax(cardService.updateCard(card));
    }
}
